package cn.kgc.spring06.config;

import cn.kgc.spring06.entity.User;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Date;

/**
 * @author: mosin
 * @version: v1.0  2022/12/2
 * 当前类相当于spring-config配置文件
 */
@Configuration
@ComponentScan("cn.kgc.spring06")
public class SpringConfig {

    @Bean("user")
    public User user(){
        User user = new User();
        user.setAge(10);
        user.setBirth(new Date());
        user.setUsername("TOM");
        return  user;
    }

    @Bean
    public Connection connection(){
        try {
            Class.forName("com.mysql.jdbc.Driver");
            String url = "jdbc:mysql:///java2217?severTimezone=UTC&useSSL=false";
            String username = "root";
            String pwd = "root";
            Connection connection = DriverManager.getConnection(url, username, pwd);
            return connection;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
